package com.hongdee.help.taskconf.controller;

import com.hongdee.help.taskconf.service.ITaskConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 本模块主要用于CRM实施过程中的遇到的某些问题，
 * 可通过接口一键进行处理
 */
@RestController
@RequestMapping("/help/taskConf")
public class TaskConfController {

    @Autowired
    private ITaskConfService taskConfService;

    /**
     * 清空指定用户的未完成的任务信息，用于二次指派任务
     * @return
     */
    @RequestMapping("/task/remove/sa/nostart")
    @ResponseBody
    public Map taskSaRemoveNoStart(@RequestParam(name = "uid", defaultValue = "") String uid,
                            @RequestParam(name = "token", defaultValue = "") String token,
                            @RequestParam(name = "saId", defaultValue = "") String saId,
                            @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskConfService.taskRemoveNoStartBySa(saId,companyId);
        map.put("success","true");
        map.put("msg","请空指定人员未完成任务SAID完成!!");
        return map;
    }


    /**
     * 清空指定用户所有任务信息，用于二次指派任务
     * @return
     */
    @RequestMapping("/task/remove/sa/all")
    @ResponseBody
    public Map taskSaRemoveAll(@RequestParam(name = "uid", defaultValue = "") String uid,
                                   @RequestParam(name = "token", defaultValue = "") String token,
                                   @RequestParam(name = "saId", defaultValue = "") String saId,
                                   @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskConfService.allTaskRemoveBySa(saId,companyId);
        map.put("success","true");
        map.put("msg","请空指定人员所有任务SAID完成!!");
        return map;
    }


    /**
     * 清空指定公司所有未完成任务信息，用于二次指派任务
     * @return
     */
    @RequestMapping("/task/remove/company/nostart")
    @ResponseBody
    public Map taskcompanyRemoveNoStart(@RequestParam(name = "uid", defaultValue = "") String uid,
                               @RequestParam(name = "token", defaultValue = "") String token,
                               @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskConfService.taskRemoveNoStatrtByCompany(companyId);
        map.put("success","true");
        map.put("msg","请空指定公司所有未完成任务SAID完成!!");
        return map;
    }

    /**
     * 清空指定公司所有未完成任务信息，用于二次指派任务
     * @return
     */
    @RequestMapping("/task/remove/company/all")
    @ResponseBody
    public Map taskcompanyRemoveAll(@RequestParam(name = "uid", defaultValue = "") String uid,
                                    @RequestParam(name = "token", defaultValue = "") String token,
                                    @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskConfService.allTaskRemoveByCompany(companyId);
        map.put("success","true");
        map.put("msg","请空指定公司所有成任务SAID完成!!");
        return map;
    }

    /**
     * 指定公司分配任务
     * @param uid
     * @param token
     * @param companyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/task/dist")
    @ResponseBody
    public Map taskDist(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskConfService.taskDistByCompany(companyId);
        map.put("success","true");
        map.put("msg","重新分配任务完成!!");
        return map;
    }

}
